import imageLoad from './imageLoad'
class createImage {
  constructor(param){
    this.param = param
    this.node = param.port.boardPort
    this.init()
  }
  init () {

  }
  async draw () {

    console.log("draw slot:", this.param)

    let newUrl = this.node.view;
    //img.src =`api/object/${this.node.id}`; // 替换为你的图片路径
    let url =newUrl; // 替换为你的图片路径
    if (process.env.NODE_ENV === 'development') {
      newUrl = this.node.view.replace('/v1', '');
      url =`api/${newUrl}`
      console.log('现在是开发模式');
      
    } else {
      console.log('现在不是开发模式');
      url = newUrl
    }
    let imageData = await imageLoad(url)
    this.img_width = imageData.width;
    this.img_height = imageData.height;
    //this.param.ctx.drawImage(imageData.img, 0, 0, param.width, param.height);
    console.log("this.param y :", this.param)
    let port = this.param.port
    // port.pos.x * this.param.ratio, port.pos.y * this.param.ratio, port.size.width * this.param.ratio, port.size.height * this.param.ratio
    this.param.ctx.drawImage(imageData.img,  port.pos.x *  this.param.ratio, port.pos.y * this.param.ratio, port.size.width * this.param.ratio, port.size.height * this.param.ratio);
   
  }
}

export default createImage